package org.example.spring.controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.example.spring.model.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RequestMapping("/return")
@Controller
public class ReturnController {
    @RequestMapping("/r1")
    public String r1(){
        return "../static/index.html";
    }
    @ResponseBody
    @RequestMapping("/r2")
    public String r2(){
        return "hello";
    }
    @ResponseBody
    @RequestMapping("/r3")
    public String r3(){
        return "<h1>一个一级标题</h1>";
    }
    @ResponseBody
    @RequestMapping("r4")
    public Model r4(){
        Model model = new Model("name",10);
        return model;
    }
    @ResponseBody
    @RequestMapping(value = "/r5",produces = "application/json;charset=utf-8")//produces设置Content-Type,同步使用charset设置编码
    public String r5(HttpServletResponse response){
        //设置状态码
        response.setStatus(401);//状态码的设置不影响页面的显示
        return "{\"OK\":1}";
    }
    /**
     * 自定义Header
     */
    @ResponseBody
    @RequestMapping(value = "/r6")//produces设置Content-Type,同步使用charset设置编码
    public String r6(HttpServletResponse response){
        //设置状态码
        response.setHeader("myHeader","myHeaderValue");
        return "设置成功";
    }
}
